$OpenBSD: patch-if_c,v 1.8 2015/03/16 15:21:58 naddy Exp $

Initial handling of NOINET6 removal (post-5.6).

XXX "no inet6" (to remove ip6 from an interface after it has been
explicitly or implicitly added) is not yet supported.

XXX "inet6 autoconf" also needs to be handled (replacement for rtsol).

--- if.c.orig	Sat May  3 23:50:07 2014
+++ if.c	Mon Mar 16 16:16:19 2015
@@ -16,7 +16,6 @@
 
 #include <stdio.h>
 #include <ctype.h>
-#include <tzfile.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -173,12 +172,12 @@ show_int(int argc, char **argv)
 	if (if_data.ifi_lastchange.tv_sec) {
 		gettimeofday(&tv, (struct timezone *)0);
 		c = difftime(tv.tv_sec, if_data.ifi_lastchange.tv_sec);
-		days = c / SECSPERDAY;
-		c %= SECSPERDAY;
-		hours = c / SECSPERHOUR;
-		c %= SECSPERHOUR;
-		mins = c / SECSPERMIN;
-		c %= SECSPERMIN;
+		days = c / (24 * 60 * 60);
+		c %= (24 * 60 * 60);
+		hours = c / (60 * 60);
+		c %= (60 * 60);
+		mins = c / 60;
+		c %= 60;
 		printf(" (last change ");
 		if (days)
 			printf("%id ", days);
@@ -628,12 +627,32 @@ set_ifxflags(char *ifname, int ifs, int flags)
 	ifr.ifr_flags = flags;
 
 	if (ioctl(ifs, SIOCSIFXFLAGS, (caddr_t)&ifr) < 0) {
-		printf("%% get_ifxflags: SIOCSIFXFLAGS: %s\n", strerror(errno));
+		printf("%% set_ifxflags: SIOCSIFXFLAGS: %s\n", strerror(errno));
 	}
 
 	return(0);
 }
 
+void
+addaf(const char *vname, int value)
+{
+	struct if_afreq ifar;
+	int s;
+
+	s = socket(AF_INET6, SOCK_DGRAM, 0);
+	if (s < 0) {
+		printf("%% socket failed: %s\n", strerror(errno));
+		return;
+	}
+
+	strlcpy(ifar.ifar_name, vname, sizeof(ifar.ifar_name));
+	ifar.ifar_af = value;
+	if (ioctl(s, SIOCIFAFATTACH, (caddr_t)&ifar) < 0)
+		printf("%% addaf: SIOCIFAFATTACH");
+
+	close(s);
+}
+
 int
 intip(char *ifname, int ifs, int argc, char **argv)
 {
@@ -1496,7 +1515,7 @@ intxflags(char *ifname, int ifs, int argc, char **argv
 	} else if (isprefix(argv[0], "mpls")) {
 		value = IFXF_MPLS;
 	} else if (isprefix(argv[0], "inet6")) {
-		value = -IFXF_NOINET6;
+		addaf(ifname, AF_INET6);
 	} else if (isprefix(argv[0], "wol")) {
 		value = IFXF_WOL;
 	} else {
@@ -1793,6 +1812,7 @@ intrtd(char *ifname, int ifs, int argc, char **argv)
 		set = 1;
 
 	if (isprefix(argv[0], "rtsol")) {
+		/* XXX BROKEN: this has been replaced with IFXF_AUTOCONF6 */
 		cmdname = "rtsol";
 		cmdpath = RTSOL;
 	} else if (isprefix(argv[0], "rtadvd")) {
